define(function(require){
    var main =require('/static/main.js');
    require('/static/ajaxfileupload.js');
    var m = new main();
    function Cont(){
        this.Fun._init();
    }
    Cont.prototype.Fun = {
        BizKey:'',
        _init:function(){

            this.getlist();
            this.bindEvent();
        },
        bindEvent:function(){
        },
        getlist:function(){
            var _this = this;
            var emdataa = [];
            var param = {};
            var sort = 0;
            var table = $('#datatable').dataTable({
                'ordering':false,
                "serverSide": true,
                "searching":false,
                'bLengthChange': false,
                'bPaginate': true,
                "bDestory": true,
                "bRetrieve": true,
                "bFilter":false,
                "bSort": false,
                "bProcessing": true,
                "autoWidth": false,
                ajax: function (data, callback, settings) {
                    //封装请求参数
                    param.PageSize = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                    param.start = data.start;//开始的记录序号
                    param.PageNo = (data.start / data.length)+1;//当前页码
                    sort = (param.PageNo-1)*param.PageSize;
                    //ajax请求数据
                    $.ajax({
                        type: "POST",
                        url: "/system/get-biz-key-val-list",
                        cache: false,  //禁用缓存
                        data: param,  //传入组装的参数
                        dataType: "json",
                        success: function (result) {
                            var returnData = {};
                            returnData.draw = data.draw;
                            returnData.recordsTotal = result.total;
                            returnData.recordsFiltered = result.total;
                            returnData.data = result.data;
                            emdataa = result.data;
                            callback(returnData);
                        }
                    });
                },
                "aoColumns":[
                    {"mDataProp": 'KeyCode'},
                    {"mDataProp": 'BizTypeName'},
                    {"mDataProp": 'KeyName'},
                    {"mDataProp": 'BizVal'},
                    {"mDataProp": 'BizKey',
                        "sClass": "option_btn",
                        "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                            // console.log(arguments);
                            $(nTd).html('<span class="btn_detial EditBtn" data-id="'+sData+'">编辑</span>');

                        }
                    }
                ]
            }).api();
            //编辑
            $(document).on('click','.EditBtn',function(){
                var BizKey = $(this).attr("data-id");
                _this.BizKey = BizKey;
                $.each(emdataa,function(k,v){
                    if(BizKey == v.BizKey){
                        $("#Edit .KeyName").val(v.KeyName);
                        $("#Edit .BizVal").val(v.BizVal);
                        $("#Edit .Comment").val(v.Comment);
                        $("#Edit").modal('show');
                        return false;
                    }
                });
            });
            $('.add').click(function(){
                var $this = $(this);
                var data = {
                    KeyName:$('.KeyName').val().trim(),
                    BizVal:$('.BizVal').val().trim(),
                    Comment:$(".Comment").val().trim(),
                    BizKey:_this.BizKey
                }
                if(data.KeyName.length < 1){
                    layer.msg('请输入键名');
                    return false;
                }
                if(data.BizVal.length < 1){
                    layer.msg('请输入键值');
                    return false;
                }
                $.ajax({
                    type: "POST",
                    url: "/system/biz-key-val-save",
                    data:data,
                    dataType: "json",
                    success: function (ret) {
                        if(ret.IsBizSuccess){
                            layer.msg('修改成功');
                            $('#Edit').modal('hide');
                            var table = $('#datatable').DataTable();
                            table.ajax.reload();
                        }else{
                            layer.msg(ret.ErrMsg);
                            return false;
                        }
                    }
                });
            })



        }

    }
    var a = new Cont();

})